Streaming
BindAI v0.1 provides an HTTP streaming endpoint for agent execution through the REST API. Streaming allows a client to receive agent output progressively instead of waiting for the complete response. The endpoint is:Streaming Architecture
A streaming request follows this general flow:StreamingResponse to return output from the agent’s stream_chat() method.
The endpoint provides an HTTP streaming boundary around BindAI agent execution. It does not define a structured event protocol for the stream.
Endpoint
The streaming endpoint is:{agent_name} path parameter identifies the configured agent that should handle the request.
For example:
404 Not Found.
Authentication
The streaming endpoint is protected by the BindAI API authentication layer. Clients must provide an API key in theAuthorization header:
BINDAI_API_KEY environment variable:
401 Unauthorized. If BINDAI_API_KEY is not configured on the server, the authentication dependency raises a server-side configuration error instead.
See the Authentication page for details.
Request Body
The streaming endpoint accepts a JSON request containing a message:message field is passed to the configured agent’s stream_chat() method.
Use a string value for the message. Refer to the generated API documentation for the exact request schema exposed by the version you are running.
Streaming Response
The endpoint returns a text-based HTTP streaming response. Conceptually:agent.stream_chat(request.message) and yields the output as a stream. Values that are not strings are converted to strings before being yielded.
The amount of data received in each chunk depends on the underlying iterator and HTTP transport. Clients must not assume a fixed number of chunks or a particular chunk size.
Streaming with cURL
Use cURL’s-N option to disable its usual output buffering:
researcher with an agent name configured in your application.
Streaming with Python
A Python HTTP client can consume the response incrementally using therequests library:
Streaming with JavaScript
A JavaScript application can consume the HTTP response using the Fetch API and a readable stream:Streaming vs Normal Execution
BindAI provides separate routes for normal and streaming agent execution. Normal execution:When to Use Streaming
Streaming is useful for interactive applications, including:- Chat interfaces.
- Agent consoles.
- Interactive assistants.
- Long generated responses.
- Content-generation interfaces.
- Developer tools.
Streaming and Model Providers
The REST API provides the HTTP streaming boundary around agent execution. The configured agent and model provider determine how the underlying execution produces output. Conceptually:Chunk Handling
Clients should treat received data as parts of a larger text response. A chunk may not represent:- A complete sentence.
- A complete word.
- A complete semantic unit.
- A complete application-level event.
Buffering
Streaming can be affected by buffering at different layers:Reverse Proxies
If a reverse proxy is placed in front of BindAI:Connection Lifetime
A streaming request keeps its HTTP response open while output is being produced. Conceptually:Client Disconnects
A client may disconnect before the response completes. For example:Streaming vs Background Runs
Streaming and background execution solve different problems. StreamingStreaming and Authentication Errors
Authentication is checked before the protected streaming endpoint can be used. When the server has a configured API key, a missing or invalid key results in HTTP401 Unauthorized rather than a successful stream.
If the server’s BINDAI_API_KEY is not configured, the authentication dependency raises a server-side configuration error.
A request that passes authentication can still fail because the agent is missing or its execution encounters an error.
Streaming and Agent Errors
A validly authenticated request can still fail during execution. Potential failure sources include:- Agent configuration.
- Model provider errors.
- Tool errors.
- Connection failures.
- External-service failures.
- Application errors.
Streaming and Tools
An agent may use tools during execution, depending on its configuration. Conceptually:Streaming and Observability
Client-facing streaming output and runtime observability are separate concerns.EventRecorder for recording events emitted through an execution context’s event bus.
Do not assume that every runtime event is included in the HTTP response or that the streaming endpoint exposes all event data. Event availability depends on the execution path and event instrumentation.
Content Type
The current v0.1 streaming route returns a text-basedStreamingResponse with the media type text/plain.
Clients should consume the response as streamed text.
The current implementation is not a Server-Sent Events (text/event-stream) endpoint. It does not define SSE-specific framing, event names, or event IDs.
Applications should not assume that each received chunk is a JSON object or a structured event.
Streaming Protocol Scope
The current v0.1 implementation provides a simple HTTP streaming interface. It does not define a complete structured streaming protocol for:- Token metadata.
- Tool-call events.
- Tool results.
- Structured model events.
- Usage events.
- Workflow events.
- Connection events.
- Separate in-stream error events.
API Documentation
FastAPI exposes API documentation for the running BindAI API application. When running locally, the documentation is commonly available at:Testing Streaming
The API package test suite can be run with:- Endpoint availability.
- Authentication.
- Agent lookup.
- Request validation.
- Streaming response behavior.
- Returned agent output.
Local Development
Start the API locally with:{agent_name} with an agent configured in your application.
Production Considerations
When deploying streaming endpoints publicly, consider:- HTTPS.
- Reverse-proxy buffering.
- Request and connection timeouts.
- Client disconnects.
- API authentication.
- Rate limiting.
- Provider latency.
- Concurrent streams.
- Resource usage.
- Monitoring.
Current v0.1 Scope
BindAI v0.1 provides:- Agent streaming through the REST API.
- Bearer API-key authentication.
- HTTP streaming responses with a
text/plainmedia type. - Incremental output from the agent’s streaming iterator.
- Compatibility with HTTP clients that support streamed responses.
Future Streaming Capabilities
Future BindAI releases could expand streaming with capabilities such as:- Structured streaming events.
- Token metadata.
- Tool-call and tool-result events.
- Usage information.
- Execution identifiers.
- Explicit stream cancellation.
- Structured error events.
- Server-Sent Events support.
- WebSocket support.
- Structured workflow streaming.
Summary
BindAI v0.1 exposes agent streaming through:message string.
The endpoint calls the configured agent’s stream_chat() method and returns the yielded output as a text-based HTTP streaming response with media type text/plain.
Streaming is useful for interactive applications, but it should not be confused with background execution or runtime observability.
The current architecture separates:
